package org.example.multiThreading.threadPool;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TestFixedThreadPool {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        /*
        FixedThreadPool
        固定容量线程池。其特点是最大线程数就是核心线程数，意味着线程池只能创建核心线程，keepAliveTime为0，
        即线程执行完任务立即回收。任务队列未指定容量，代表使用默认值Integer.MAX_VALUE。适用于需要控制并发线程的场景。
        */
        //创建FixedThreadPool
        ExecutorService executorService = Executors.newFixedThreadPool(5);

        //创建TestCallable，并加入线程池
        for (int i = 0; i < 10; i++) {
            TestCallable callable = new TestCallable();
            System.out.println(executorService.submit(callable).get());
        }

        //关闭线程池
        executorService.shutdown();
    }
}
